<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>库存期初建账管理</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/common/change/change.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		initVaccName(bsProduct.companyCode,bsProduct.vaccineId);
		initVaccCompanyName(bsProduct.companyCode)
		initgNum(bsVaccine.gNum,bsVaccine.gName);
		$(".vaccineCompany").change(function(){
			var vaccId = $(this).val();
			initCompanyName($(this).val());
			if(vaccId == ""){
				initVaccCompanyName("");
			}
		});
		$(document).on("click","#union",function(){
			var $tr = $(this).closest("tr");
			var obj = {
					id : "",
                    index : guid(),
					productId : $tr.find('[data-name="productId"]').attr('data-col'),
					batchnoId : $tr.find('[data-name="batchnoId"]').attr('data-col'),
					name : $tr.find('[data-name="vaccineName"]').attr('data-col'),
					vaccineId : $tr.find('[data-name="vaccineId"]').attr('data-col'),
					sort : $tr.find('[data-name="cType"]').attr('data-col'),
					companyName : $tr.find('[data-name="companyName"]').attr('data-col'),
					companyCode : $tr.find('[data-name="companyCode"]').attr('data-col'),
					batchno : $tr.find('[data-name="batchno"]').attr('data-col'),
					secondBatchno : $tr.find('[data-name="secondBatchno"]').attr('data-col'),
					spec : $tr.find('[data-name="specOrigin"]').attr('data-col'),
					dose : $tr.find('[data-name="dose"]').attr('data-col'),
					storenum : $tr.find('[data-name="storenum"]').attr('data-col'),
					storenumF : $tr.find('[data-name="storenumF"]').attr('data-col'),
					vaccExpDate : $tr.find('[data-name="outBoundDate"]').attr('data-col'),
					orignprice : $tr.find('[data-name="orignprice"]').attr('data-col'),
					sellprice : $tr.find('[data-name="sellprice"]').attr('data-col'),
					batchType : $tr.find('[data-name="batchType"]').attr('data-col'),
					largePackage : $tr.find('[data-name="largePackage"]').attr('data-col'),
					smallPackage : $tr.find('[data-name="smallPackage"]').attr('data-col'),
					num : '',
					remarks : ''
				};
			if(obj.outBoundDate == '' || obj.outBoundDate == '-'){
				layer.msg("该批号的有效日期不能为空!");
				return;
			}
			var num_reg = /^\+?[1-9][0-9]*$/;
			debugger;
			if(obj.batchType == '1'){
				if (!num_reg.test(obj.spec)) {
					layer.msg("该批号的规格的格式不正确!");
					return;
				}
				$.ajax({
					url:"${ctx}/company/bsCompanyConfig/checkConfig",
					type: "POST",
					data:{
			              "vaccineId":    obj.vaccineId,
			              "companyCode":  obj.companyCode
			             },
					async : false,
					success:function(data){
						if(data.result == true){
							parent.layerDiv(obj);
						}else{
							layer.msg("该批号暂不支持选用!");
							return;
						}	
					},
					error : function() {
						return;
					}
			    }); 
			}else{
				parent.layerDiv(obj);
			}
		});
		/* $("#check_ok").click(function(){
			$(this).attr('disabled',true); 
			//获取所有的选择列
			var data=[];
			debugger;
			$("#contentTable").find(":checkbox:checked").each(function(key,value){
			 	var $tr = $(this).parent().parent().parent();
			 	var tds = $tr.find("td");
				var tr = {
					id : "",
					index : guid(),
					productId : $tr.find('[data-name="productId"]').attr('data-col'),
					batchnoId : $tr.find('[data-name="batchnoId"]').attr('data-col'),
					name : $tr.find('[data-name="vaccineName"]').attr('data-col'),
					sort : $tr.find('[data-name="cType"]').attr('data-col'),
					companyName : $tr.find('[data-name="companyName"]').attr('data-col'),
					companyCode : $tr.find('[data-name="companyCode"]').attr('data-col'),
					batchno : $tr.find('[data-name="batchno"]').attr('data-col'),
					secondBatchno : $tr.find('[data-name="secondBatchno"]').attr('data-col'),
					spec : $tr.find('[data-name="specOrigin"]').attr('data-col'),
					dose : $tr.find('[data-name="dose"]').attr('data-col'),
					storenum : $tr.find('[data-name="storenum"]').attr('data-col'),
					storenumF : $tr.find('[data-name="storenumF"]').attr('data-col'),
					vaccExpDate : $tr.find('[data-name="outBoundDate"]').attr('data-col'),
					orignprice : $tr.find('[data-name="orignprice"]').attr('data-col'),
					sellprice : $tr.find('[data-name="sellprice"]').attr('data-col'),
					batchType : $tr.find('[data-name="batchType"]').attr('data-col'),
					num : ''
				}
				data.push(tr);
			});
			if(data.length==0){
				layer.msg("至少选择一条记录",{"icon":7, "time":1000});
				$(this).attr('disabled',false); 
				return ;
			}
 			parent.layer.closeAll();
			parent.layerDiv(data);
		}); */

		$("#reset").click(function() {
			reset();
		});

	});

	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}

	var bsProduct = JSON.parse('${fns:toJson(bsProduct)}');
	var bsVaccine = JSON.parse('${fns:toJson(bsProduct.bsVaccine)}');
	function finishVaccine2Company() {
		if (bsProduct && bsProduct["vaccineId"]) {
			$("#vaccineId").val(bsProduct.vaccineId);
			$("#vaccineId").select2();
			$("#vaccineId").change();
		}
	}
	function finishSelectCompany() {
		$("#companyCode").val(bsProduct.companyCode);
		$("#companyCode").select2();
	}
	function reset() {
		$("#bsVaccineBatchno-batchType").val("").select2();
		$('#vaccineId').val("").select2();
		$('#companyCode').val("").select2();
		$('#batchno').val("");
		$('#cType').val("").select2();
		$("input[name=beginVaccExpDate]").val("");
		$("input[name=endVaccExpDate]").val("");
	}
	function closeLayer(){
		parent.layer.closeAll();
	}
</script>

<style type="text/css">
	body{
		padding:10px;
	}
	.minWidth {
		min-width: 177px;
	}	
	#contentTable td ,#contentTable th{
		text-align: center;
	}
	#contentTable tbody tr td{
		font-size: 13px;
	}
</style>
</head>
<body>
	<%-- <ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/vaccinate/bsProduct/">库存列表</a></li>
	</ul> --%>
	<form:form id="searchForm" modelAttribute="bsProduct" action="${ctx}/vaccinate/bsProduct/getList" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="ordertype" name="ordertype" type="hidden" value="${bsProduct.ordertype}"/>
		<table class="table table-bordered">
			<tr>
			    <th>疫苗/注射器：</th>
				<td>
					<form:select path="bsVaccineBatchno.batchType" id="bsVaccineBatchno-batchType" class="span2 minWidth">
						<form:option value="" label="--请选择--"/>
						<form:options items="${fns:getDictList('batch_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select> 
				</td>
			    <th>疫苗类型：</th>
				<td>
					<form:select path="cType" id="cType" class="span2 minWidth">
						<form:option value="" label="--请选择--"/>
						<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
					</form:select> 
				</td>
				<th>疫苗批号：</th>
				<td>
					<form:input path="batchno" id="batchno" class="span2 minWidth" />	
				</td>
			</tr>
			<tr>
				<th>疫苗名称:</th>
				<td>
					<form:select path="vaccineId" id="vaccineId" class="span2 minWidth vaccineCompany" >
						<form:option value=""  label="--请选择--"/>
					</form:select>
				</td>
				<th>生产企业：</th>
				<td>
					<form:select path="companyCode" id="companyCode" class="span2 minWidth changeCompany vaccCompanyName">
						<form:option value="" label="--请选择--"/> 
					</form:select>
				</td>
				<th>疫苗大类:</th>
				<td>
					<form:select path="bsVaccine.gNum" id="bsVaccine.gNum" class="span2 minWidth vaccinegName" >
						<form:option value=""  label="--请选择--"/>
					</form:select>
				</td>
			</tr>
			<tr>
				<th>起始有效期：</th>
				<td>
					<input name="beginVaccExpDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${bsProduct.beginVaccExpDate}" pattern="yyyy-MM-dd"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
				</td>
				<th>截止有效期：</th>
				<td>
					<input name="endVaccExpDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${bsProduct.endVaccExpDate}" pattern="yyyy-MM-dd"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
				</td>
				<th>失效：</th>
				<td>
					<form:radiobuttons path="type" items="${fns:getDictList('yes_no')}"
						itemLabel="label" itemValue="value" class="required" />
				</td>
			</tr>
		</table>
		<div>
			<button id="btnSubmit" class="btn btn-primary" type="submit">查询</button>
			<button id="reset"  class="btn btn-primary" type="button">重置</button>
			<button  class="btn btn-primary" onclick="closeLayer()" type="button">关闭窗口</button>
		</div>
	</form:form>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>操作</th>
				<th>疫苗名称</th>
				<th>疫苗属性</th>
				<th>疫苗生产企业</th>
				<th>批号</th>
				<th>规格</th>
				<th>剂量</th>
				<th>有效期</th>
				<th>成本价</th>
				<th>库存数量</th>
				<th>可用库存</th>
				<!-- <th>最小分包装(支/盒)</th> -->
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="bsProduct">
			<tr <%-- data-data='${fns:toJson(bsProduct) }' --%>>
				<td>
					<!-- <input type="checkbox"> -->
					<input type="button" style="border:none;background-color:#ffffff;" id="union" value="关联"/>
				</td>
				<td data-name = "vaccineName" data-col = "${bsProduct.bsVaccineBatchno.vaccineName}">
					${bsProduct.bsVaccineBatchno.vaccineName}
				</td>
				<td data-name = "vaccineId" data-col = "${bsProduct.bsVaccineBatchno.vaccineId}" style="display:none">
					${bsProduct.bsVaccineBatchno.vaccineId}
				</td>
				<td data-name = "cType" data-col = "${bsProduct.cType}">
					${fns:getDictLabel(bsProduct.cType, "bs_vaccine_type", "")}
				</td>
				<td data-name = "companyName" data-col = "${bsProduct.bsVaccineBatchno.companyName}">
					${bsProduct.bsVaccineBatchno.companyName}
				</td>
				<td data-name = "companyCode" data-col = "${bsProduct.bsVaccineBatchno.companyCode}" style="display:none">
					${bsProduct.bsVaccineBatchno.companyCode}
				</td>
				<td data-name = "batchno" data-col = "${bsProduct.bsVaccineBatchno.batchno}">
				    ${bsProduct.bsVaccineBatchno.batchno}
					<c:if test="${not empty bsProduct.bsVaccineBatchno.secondBatchno}">
				        <span title="(查询批号时不需要带入亚批号)" style="color: #2fa4e7;"> -${bsProduct.bsVaccineBatchno.secondBatchno}</span>
				    </c:if>
				</td>
				<td data-name = "secondBatchno" data-col = "${bsProduct.bsVaccineBatchno.secondBatchno}" style="display:none;" id="hidetd">
					${bsProduct.bsVaccineBatchno.secondBatchno}
				</td>
				<td data-name = "spec" data-col = "${bsProduct.bsVaccineBatchno.spec}">
					${bsProduct.bsVaccineBatchno.spec}
				</td>
				<td data-name = "dose" data-col = "${bsProduct.bsVaccineBatchno.dose}">
					${bsProduct.bsVaccineBatchno.dose}
				</td>
				<td data-name = "outBoundDate" data-col = "<fmt:formatDate value="${bsProduct.bsVaccineBatchno.outBoundDate}" pattern="yyyy-MM-dd"/>">
					<fmt:formatDate value="${bsProduct.bsVaccineBatchno.outBoundDate}" pattern="yyyy-MM-dd"/>
				</td>
				<td data-name = "orignprice" data-col = "${bsProduct.orignprice}" style="text-align: right;padding-right: 10px;">
					${bsProduct.orignprice}
				</td>
				<td data-name = "storenum" data-col = "${bsProduct.storenum}">
					${bsProduct.storenum}
				</td>
				<td data-name = "productId" data-col = "${bsProduct.id}" style="display:none">
					${bsProduct.id}
				</td>
				<td data-name = "sellprice" data-col = "${bsProduct.sellprice}" style="display:none">
					${bsProduct.sellprice}
				</td>
				<td data-name = "batchnoId" data-col = "${bsProduct.bsVaccineBatchno.id}" style="display:none">
					${bsProduct.bsVaccineBatchno.id}
				</td>
				<td data-name = "storenumK" data-col = "${bsProduct.storenum-bsProduct.storenumF}">
					${bsProduct.storenum-bsProduct.storenumF}
				</td>
				<td data-name = "storenumF" data-col = "${bsProduct.storenumF}" style="display:none">
					${bsProduct.storenumF}
				</td>
				<td data-name = "specOrigin" data-col = "${bsProduct.bsVaccineBatchno.specOrigin}" style="display:none">
					${bsProduct.bsVaccineBatchno.specOrigin}
				</td>
				<td data-name = "batchType" data-col = "${bsProduct.bsVaccineBatchno.batchType}" style="display:none">
					${bsProduct.bsVaccineBatchno.batchType}
				</td>
				<td data-name = "largePackage" data-col = "${bsProduct.bsVaccineBatchno.largePackage}" style="display:none">
					${bsProduct.bsVaccineBatchno.largePackage}
				</td>
				<td data-name = "smallPackage" data-col = "${bsProduct.bsVaccineBatchno.smallPackage}" style="display:none">
					${bsProduct.bsVaccineBatchno.smallPackage}
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>